package newpackage;
import java.util.Properties;  
    import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
      
   public  class SendEmailKey {  
     public static void sendMail(String toMail,String contt) throws AddressException, MessagingException {  
      
//      String host="mail.javatpoint.com";  
//      final String user="dinesh@uniqtechnologies.co.in";//change accordingly  
//      final String password="UniqTech";//change accordingly  
//        
//      String to=toMail;//change accordingly  
//      
//       //Get the session object  
//       Properties props = new Properties();  
//       props.put("mail.smtp.host",host);  
//       props.put("mail.smtp.auth", "true");  
//         
//       Session session = Session.getDefaultInstance(props,  
//        new javax.mail.Authenticator() {  
//         protected PasswordAuthentication getPasswordAuthentication() {  
//        return new PasswordAuthentication(user,password);  
//          }  
//        });  
//      
//       //Compose the message  
//        try {  
//         MimeMessage message = new MimeMessage(session);  
//         message.setFrom(new InternetAddress(user));  
//         message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));  
//         message.setSubject("Signature from server");  
//         message.setText(content);  
//           
//        //send the message  
//         Transport.send(message);  
//      
//         System.out.println("message sent successfully...");  
//       
//         } catch (MessagingException e) {e.printStackTrace();}  
//     }  
     boolean debug = true;
     Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");

Session session = Session.getDefaultInstance(props,new javax.mail.Authenticator() {

protected PasswordAuthentication getPasswordAuthentication() 
{
return new PasswordAuthentication("testsamplecloud","asdf123!@");
}
});
//String s="test2cloud2@gmail.com";

String[] too=toMail.split(",");
session.setDebug(debug);
Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress("testsamplecloud@gmail.com");
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[too.length];
for (int i = 0; i < too.length; i++) {
addressTo[i] = new InternetAddress(too[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);

// Setting the Subject and Content Type
msg.setSubject("Notification From Admin");

msg.setContent(contt, "text/plain");
Transport.send(msg);        
     }
   }